/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package PasswrdChk01.Regras;

import InterfacesPasswordChecker01.BonusFactory01;
import PasswrdChk01.Componentes.Simbolos;

/**
 *
 * @author LABCCET
 */
public class Bonus implements BonusFactory01{
    final int BONUS_MINUSCULAS = 1;
    final int BONUS_MAIUSCULAS = 5;
    final int BONUS_DIGITOS_UNICO = 5;
    final int BONUS_DIGITOS_ACIMA_DE_DOIS = 10;
    final int BONUS_SIMBOLOS_UNICO = 5;
    final int BONUS_SIMBOLOS_ACIMA_DE_UM = 10;
    final int BONUS_MULTITIPOS_CARACTERES = 2;
    
    String password;

    public Bonus(String password) {
        this.password = password;
    }
    
    @Override
    public int calcularBonusMinusculas() {
        //<=====Bonus.calcularBonusMinusculas
        int pontos = 0;
        for (char a : password.toCharArray()) {
            if (Character.isLowerCase(a)) {
                return BONUS_MINUSCULAS;
            }
        }
        return pontos;
    }

    @Override
    public int calcularBonusMaiusculas() {
        //<=====Bonus.calcularBonusMaiusculas
        int pontos = 0;
        
        for (char a : password.toCharArray()) {
            if (Character.isUpperCase(a)) {
                return BONUS_MAIUSCULAS;
            }
        }
        return pontos;
    }

    @Override
    public int calcularBonusSimbolos(Simbolos simbolos) {
        
        int counter = 0;
        char[] arraySenha = password.toCharArray();
        for (char c : arraySenha) {
            if (simbolos.isSimbol(c)) {
                counter++;
            }
        }
        if (counter <= 0) {
            return 0;
        }
        return (counter > 1) ? BONUS_SIMBOLOS_ACIMA_DE_UM : BONUS_SIMBOLOS_UNICO;
    }

    @Override
    public int calcularBonusTamanhoSenha() {
        int total = 0;
        if (password.length() <= 5) {
            return total += 3;
        } else if (password.length() > 5 && password.length() <= 8) {
            return total += 6;
        } else if (password.length() > 8 && password.length() <= 16) {
            return total += 12;
        } else if (password.length() > 16) {
            return total += 18;
        }
        return total;
    }

    @Override
    public int calcularBonusEntreTiposCaracteres(int funcao1, int funcao2) {
        return (funcao1 > 0 && funcao2 > 0) ? BONUS_MULTITIPOS_CARACTERES : 0;
    }

    @Override
    public int calcularBonusLetras() {
        return calcularBonusMaiusculas() + calcularBonusMinusculas();
    }

    @Override
    public int calcularBonusDigitos() {
      
        int counter = 0;
        char[] arraySenha = password.toCharArray();
        for (char c : arraySenha) {
            if (Character.isDigit(c)) {
                counter++;
            }
        }
        if (counter <= 0) {
            return 0;
        }
        return (counter > 2) ? BONUS_DIGITOS_ACIMA_DE_DOIS : BONUS_DIGITOS_UNICO;
        
    }

    @Override
    public int calcularBonusMultiTiposCaracteres() {
        //<======Bonus.totalizarBonus
        int bonus = 0;
        bonus += calcularBonusEntreTiposCaracteres(calcularBonusMaiusculas(), calcularBonusMinusculas());
        bonus += calcularBonusEntreTiposCaracteres(calcularBonusLetras(), calcularBonusDigitos());
        if (calcularBonusLetras() > 0 || calcularBonusDigitos() > 0) {
            bonus += calcularBonusEntreTiposCaracteres(BONUS_MULTITIPOS_CARACTERES, calcularBonusSimbolos(new Simbolos()));
        }
        return bonus;
    }

    @Override
    public int somarDigitos() {
        int total = 0;
        for (char a : password.toCharArray()) {
            if (Character.isDigit(a)) {
                total++;
            }
        }
        return total;
    }
    
}
